home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
fonttools
/
clonewid.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
152 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
* clonewid -
* Use widths from another font.
*
* Paul Haeberli - 1991
*
*/
#include "stdio.h"
#include "objfnt.h"
objfnt *ofnt, *wfnt;
main(argc,argv)
int argc;
char **argv;
{
short val;
float pos;
float ixpos, iypos;
float xpos, ypos;
int dx, dy;
int xmove, ymove;
if( argc<4 ) {
fprintf(stderr,"usage: clonewid orig.of width.of out.of\n");
exit(1);
}
ofnt = readobjfnt(argv[1]);
if(!ofnt) {
fprintf(stderr,"clonewid: can't open input file\n");
exit(1);
}
wfnt = readobjfnt(argv[2]);
if(!wfnt) {
fprintf(stderr,"clonewid: can't open input file\n");
exit(1);
}
clonewidths(ofnt,wfnt);
writeobjfnt(argv[3],ofnt);
}
mag(v)
int v;
{
if(v<0)
return -v;
else
return v;
}
clonewidths(ofnt,wfnt)
objfnt *ofnt, *wfnt;
{
int i, dx, dy;
chardesc *ocd, *wcd;
int oxmin, oxmax, oymin, oymax;
int wxmin, wxmax, wymin, wymax;
int mindx, maxdx, mindy, maxdy;
for(i=ofnt->charmin; i<=ofnt->charmax; i++) {
ocd = getchardesc(ofnt,i);
wcd = getchardesc(wfnt,i);
if(ocd && wcd) {
fincharbbox(ofnt,i,&oxmin,&oxmax,&oymin,&oymax);
fincharbbox(wfnt,i,&wxmin,&wxmax,&wymin,&wymax);
mindx = wxmin-oxmin;
maxdx = wxmax-oxmax;
mindy = wymin-oymin;
maxdy = wymax-oymax;
if(mag(maxdx)<mag(mindx))
dx = maxdx;
else
dx = mindx;
if(mag(maxdy)<mag(mindy))
dy = maxdy;
else
dy = mindy;
ocd->movex = wcd->movex;
ocd->movey = wcd->movey;
translatechar(ofnt,i,dx,dy);
}
}
}
static int xmin, xmax, ymin, ymax;
static bboxcalc(v)
short v[2];
{
if(v[0]<xmin)
xmin = v[0];
if(v[1]<ymin)
ymin = v[1];
if(v[0]>xmax)
xmax = v[0];
if(v[1]>ymax)
ymax = v[1];
}
int xtrans, ytrans;
static warpfunc(s)
short s[2];
{
s[0] = s[0] + xtrans;
s[1] = s[1] + ytrans;
}
translatechar(fnt,c,dx,dy)
objfnt *fnt;
int c, dx, dy;
{
xtrans = dx;
ytrans = dy;
applytocharverts(fnt,c,warpfunc);
}
fincharbbox(fnt,c,rxmin,rxmax,rymin,rymax)
objfnt *fnt;
int c;
int *rxmin, *rxmax, *rymin, *rymax;
{
chardesc *cd;
xmin = ymin = NOBBOX;
xmax = ymax = -NOBBOX;
cd = getchardesc(fnt,c);
if(cd)
applytocharverts(fnt,c,bboxcalc);
*rxmin = xmin;
*rxmax = xmax;
*rymin = ymin;
*rymax = ymax;
}